/* 
    Document   : acd.main
    Created on : 14/11/2012, 03:16:31 PM
    Author     : acazares
    Description:
        script base
*/
var servlet = 'requestController.jsf';
$(function(){    
    $(".userMenuBox").bind('click', function(){
        $('.menuUser').fadeIn('slow', function() {
            setTimeout(function(){$('.menuUser').fadeOut('slow')}, 3000);            
        });
    });
    setInterval(function(){        
        $(".blinking").fadeToggle("slow");        
    }, 300);
    $("#lblRegistro").bind("click", function(){
       location.href="faces/usuario.xhtml?action=nuevo"; 
    });
    
    
    $("#formLogin").submit(function(e){
        if($('#username').val().length==0){
            $('#username').css("background-color","yellow");
            $('#username').focus();            
        }else{
            $('#username').css("background-color","#fff");        
        }
        
        if($('#pass').val().length==0){
            $('#pass').css("background-color","yellow");
            $('#pass').focus();
            return false;
        }else{
            $('#pass').css("background-color","#fff");
        }
        if($('#username').val().length==0){
            return false;
        }
        
        extras = 'user='+$('#username').val()+'&pass='+$('#pass').val()
        $.ajax({     
            dataType : "json",
            url : servlet+'?action=login&'+extras,            
            //url : 'requestController.jsp?action=logout',
            success: function(data) {//alert(data);
                JSONdata = eval(data)
                if(JSONdata.id !=null){
                    location.href='?';
                }else{
                    $("#msgErrorLogin").css("display","inline")
                    $("#username").val("");
                    $("#pass").val("");
                }
                                
            }
        });
        return false;
    });
    
    $("#btnLogout").bind('click', function(){
        $.ajax({     
            dataType : "json",
            url : servlet+'?action=logout',            
            //url : 'requestController.jsp?action=logout',
            //url : 'http://localhost:8080/jv3/faces/index.xhtml',
            success: function(data) {//alert(data);
                location.href='?';                
            }
        });
    });
      
      
});



